<template>
  <van-picker
    title="选择性别"
    show-toolbar
    :columns="columns"
    @confirm="submit"
    @cancel="$emit('close')"
    :default-index="value"
  />
</template>

<script>
import { editUserProfile } from '@/api/user'
export default {
  name:'UpdateGender',
  props:{
    // 接收性别
    value:{
      type:Number
    }
  },
  data() {
    return {
      columns: ['男','女']
    }
  },
  methods: {
    async submit(value, index) {
      // value 选中的文字，  index是对应文字所在的索引
      try {
        await editUserProfile({
          gender:index
        })
        this.$emit('input',index)
        this.$emit('close')
      } catch (error) {
        return this.$toast.fail('修改失败')
      }
    }
  },
}
</script>

<style>

</style>